﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" id="teacherForm">
<head>
    <title>课件维护</title>
   
    <script type="text/javascript">
    var mainform;
    var viewType = "${viewType}";
    var flag=false;

    $(document).ready(function() {
    	$('#fileupload').uploadify({
            swf      : '${ctx}/static/uploadify/uploadify.swf',
            uploader : '${ctx}/qso/aid/uploadFile',
            width: 100,
    		height:22,
    		multi: false,
    		auto: false,
    		fileObjName: 'file',
    		fileTypeExts: '*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.txt;',
    		fileSizeLimit: 52428800,
    		checkExisting: true,
    		method: 'post',  
    		removeCompleted : false,
    		buttonText:'浏览',
    		queueSizeLimit: 1,
    		displayData: 'percentage',
    		queueID:'foo',
    		cancelImg: '/qso/static/uploadify/uploadify-cancel.png',
    		onUploadProgress: function(file, fileBytesLoaded, fileTotalBytes){
    			
    		 },
    		 onUploadSuccess : function(file, data, response){
    			 flag=true;
    		 },
    		 onQueueComplete: function() {
    		 },
    		 onUploadError : function(file, errorCode, errorMsg){
    			 flag=false;
    		 }
        });
    });
    
    function uploadifyUpload(){ 
 	   $('#fileupload').uploadify('upload','*');
   	} 
    
    $(function (){
    
        mainform=$("#mainform");
        
        mainform.ligerForm();
        
        //如果是修改视图,主键不可编辑
        //if(viewType=="modify"){
        	 $("#id").attr("readonly", "readonly").removeAttr("validate");
        //}
        
        //如果是详细试图,所有字段不可编辑
        if(viewType=="detail"){
        	$("input,select,textarea",mainform).attr("readonly", "readonly");
        }else{
            $.metadata.setType("attr", "validate");
            LG.validate(mainform);
        }
        
        //渲染按钮
        LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : save);  
        
    });
    
    function save(){
    	if(flag){
    		LG.submitForm(mainform, function (result) {
            	if(typeof(result)=="string"){
            		result=eval("("+result+")");
            	}
                if (!result.success) {
                    LG.showError('错误:' + data.message);
                }
                else { 
                    LG.showSuccess('保存成功', function () { 
                       LG.callParent("clsList");
                    });
                }
            });
    	}else{
    		LG.showError('请上传附件');
    	}
     /*     */
    }
    function cancel(){
        var win = window.parent || window;
        if(win.dialog){
        	win.dialog.close();
        }
    }
    
 </script>
</head>

<body>
    <form name="mainform" method="post"  id="mainform" action="${ctx }/qso/aid/save">
        <input type="hidden" name="viewType" value="${viewType}"/>
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 95%; margin-top:10px; margin-left:15px;">
            <tr>
                <td align="right" class="l-table-edit-td">课件代码:</td>
                <td align="left" class="l-table-edit-td">
                	${command.id}
                	<input name="id" type="hidden" id="id" value="${command.id}" ltype="text" />
                </td>
                <td align="right" class="l-table-edit-td">上传教师:</td>
                <td align="left" class="l-table-edit-td">
               	 	${command.teaid.terName}
                	<input name="terid" type="hidden" id="terid" value="${command.teaid.terId}" validate="{required:true}"/>
                </td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td">课件名称:</td>
                <td align="left" class="l-table-edit-td">
                	<input name="name" type="text" id="name" value="${command.name}" validate="{required:true}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
                <td align="right" class="l-table-edit-td">是否共享:</td>
                <td align="left" class="l-table-edit-td">
                	<select id="share" name="share" style="width: 100px;" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>>
							<option value="0">是</option>
							<option value="1">否</option>
					</select>
                </td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">课件说明:</td>
                <td align="left" class="l-table-edit-td" colspan="3"> 
                <textarea cols="100" rows="1" class="l-textarea" id="intro" name="intro" style="width:500px" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> >${command.intro}</textarea>
                </td> <td align="left"></td>
           </tr>
           <tr>
                <td align="right" class="l-table-edit-td" valign="top">附件:</td>
                <td align="left" class="l-table-edit-td" colspan="3"> 
					<c:forEach items="${attachments}" var="attachment">
						<div id="deFile" class="l-table-edit-td">${attachment.originalName} 
						<a onclick="return downloadAttach('${attachment.id}');"	 >下载</a>
						<c:if test="${viewType!='detail'}">
						<a onclick="return deleteAttach('${attachment.id}');"	 >删除</a>
						</c:if>
						</div>
						
					</c:forEach>
					<c:if test="${viewType!='detail'}">
 					<div id="upFile" <c:if test="${attachments!=null}">style="display:none" </c:if> >
					<input type="file" id="fileupload"/>
                	<div id="foo" style="max-width:350px;width:350px;"></div>
                	<div id="info"></div>
                	<div id="btnCon" style="margin-top:5px;">
      	  			<input type="button" name="start" value="开始上传" onclick="uploadifyUpload()" style="margin-left:auto;margin-right: auto;"/>
                  	</div> 
                  	</div>
                  	</c:if>
                </td>
           </tr>
            <tr style="margin-bottom:100px;">
                <td align="right" class="l-table-edit-td" valign="top">备注:</td>
                <td align="left" class="l-table-edit-td" colspan="3"> 
                <textarea cols="100" rows="3" class="l-textarea" id="remark" name="remark" style="width:500px"<c:if test="${viewType=='detail'}">disabled="disabled"</c:if> >${command.remark}</textarea>
                </td> <td align="left"></td>
           </tr>
        </table>
    </form>
    <div style="height:80px"></div>
</body>

<script>
 function deleteAttach(id){
	 var url='${ctx}/qso/aid/deleteFile?id='+id;
	 $.post(url,null,function(data){
		 if(data=='true'){
			 $("#deFile").remove();
			 $("#upFile").css("display","block");
		 }
	 });
	 
 }
 
 function downloadAttach(id){
	 var url='${ctx}/qso/aid/downloadFile?id='+id;
	 window.location = url;
	//$.post(url,null,function(data){
		
	//});
	 return false;
 }
</script>


</html>
